<template>
	<view class="container-main" :style="{
		     '--top-bar-height':mp.topBarHeight + 'px',
	         '--safe-area-bottom':mp.systemInfo.safeAreaInsets.bottom + 'px'}">
		<view class="container-main-top"></view>
		<!-- #ifdef MP-WEIXIN -->
		<go-back>充值记录</go-back>
		<!-- #endif -->
		<!-- 推荐 -->
		<view class="section section-recommend" v-if="browseList.loading">
			<view class="recommend">
				<view class="recommend-list" style="width: 100%">
					<template v-for="(item,index) in browseList.list">
						<view class="recommend-item" v-if="item.orderType != 1" :key="item.skitId">
							<view class="recommend-top" v-if="item.rechargeType == 0 || !item.rechargeType">
								<view class="title-r">充值金币+{{item.buyVirtualCurrency}}币</view>
								<view class="bi">余额{{item.remainderAmount}}币</view>
							</view>
							<view class="recommend-top" v-else-if="item.rechargeType == 1">
								<view class="title-r">充值会员</view>
								<view class="bi">{{item.vipDay}}天</view>
							</view>
							<view class="recommend-top" v-else-if="item.rechargeType == 2">
								<view class="title-r">解锁全集</view>
								<view class="bi">{{item.skitName}}</view>
							</view>
							<view class="recommend-bottom">
								<view class="pirce">消费金额：{{item.payTotalAmount}}元</view>
								<view class="time">{{item.time}}</view>
							</view>
						</view>
					</template>
				</view>
				<view v-show="browseList.loading && browseList.list.length <= 0">
					<empty fixed></empty>
				</view>
				<view v-show="load.loading">
					<uv-load-more :status="load.status" :loading-text="load.loadingText" :nomore-text="load.nomoreText" :line="load.status == 'nomore'" />
				</view>
			</view>
		</view>
		<!-- #ifdef MP-TOUTIAO -->
		<button class="menu-item-btn" data-im-id="miliner." open-type="im"></button>
		<!-- #endif -->
	</view>
</template>


<script>
	const app = getApp();
	import mp from "@/mixins/mp.js";
	import empty from '@/components/empty/empty.vue';
	import goBack from '@/components/back/back.vue';
	import { getOrderPage } from '@/common/api';
	import { timeFormat } from '@/uni_modules/uv-ui-tools/libs/function/index.js';
	export default {
		mixins: [mp],
		components: {
			empty,
			goBack
		},
		data() {
			return {
				browseList: {
					list: [],
					hasMore: false,
					loading: false,
					page: 1,
				},
				load: {
					loading: false,
					status: 'loading',
					loadingText: '努力加载中',
					nomoreText: '没有更多了'
				},
			}
		},
		onLoad(option) {
			this.getPageData();
		},
		onShow() {},
		onHide() {},
		/**
		 * 触底
		 */
		onReachBottom() {
			if (this.browseList.hasMore && this.browseList.loading) {
				this.load.loading = true
				this.requestMyBrowse()
			}
		},
		watch: {},

		methods: {
			loadMore() {
				if (this.browseList.hasMore && this.browseList.loading) {
					this.load.loading = true
					this.requestMyBrowse()
				}
			},
			// 加载页面数据
			getPageData: function(callback) {
				Promise.all([this.requestMyBrowse()]).then(() => {
					callback && callback()
				}).catch(() => {
					callback && callback()
				});
			},
			requestMyBrowse() {
				return new Promise((resolve, reject) => {
					let params = { pageNo: this.browseList.page, pageSize: 11, orderType: 0 };
					getOrderPage(params).then((result) => {
						let total = result.total;
						let data = result.list;
						let { page, list, hasMore } = this.browseList;
						if (1 == page) {
							list.length = 0;
						}
						data.forEach(item => {
							item.time = timeFormat(item.createTime, 'yyyy-mm-dd hh:MM:ss')
						})
						list = [...list, ...data];
						hasMore = total > list.length;
						if (hasMore) {
							page++;
							this.load.loading = false;
						} else {
							this.load.status = 'nomore';
							this.load.loading = list.length > 4;
						}
						resolve({ data: data.length, hasMore });
						this.browseList.page = page;
						this.browseList.list = list;
						this.browseList.hasMore = hasMore;
						this.browseList.loading = true;
					}).catch((err) => {
						this.browseList.loading = true;
						reject();
					});
				});
			},
		}
	}
</script>


<style lang="scss">
	page {
		/* #ifdef MP-WEIXIN */
		background: #000;
		/* #endif */
		// background-image: url('https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/peng-jc/new_bg.png');
		// background-repeat: no-repeat;
		// background-size: 100% 1071rpx;
		// background-position: 0 0;
	}

	.container-main {
		box-sizing: border-box;
		padding-top: calc(var(--top-bar-height) + 30rpx);
		padding-bottom: calc(var(--safe-area-bottom) + 30rpx);

		.container-main-top {
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			width: 100%;
			height: calc(var(--top-bar-height) + 30rpx);
			background: #000;
			// background-image: url('https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/peng-jc/new_bg.png');
			// background-repeat: no-repeat;
			// background-size: 100% 1071rpx;
			// background-position: 0 0;
		}


		.section {
			margin-bottom: 64rpx;

			.title {
				font-weight: 900;
				font-size: 36rpx;
				color: #FFFFFF;
				line-height: 50rpx;
				box-sizing: border-box;
				padding-left: 36rpx;
				margin-bottom: 24rpx;
			}
		}

		.section-recommend {
			margin-bottom: 0;

			.recommend {
				box-sizing: border-box;
				padding: 0 36rpx;

				.recommend-list {
					width: 100%;

					.recommend-item {
						box-sizing: border-box;
						padding: 24rpx 0;

						.recommend-top {
							display: flex;
							align-items: center;
							justify-content: space-between;
							margin-bottom: 24rpx;

							.title-r {
								font-weight: 500;
								font-size: 32rpx;
								color: #FFFFFF;
								line-height: 45rpx;
								text-align: center;
							}

							.bi {
								font-weight: 500;
								font-size: 32rpx;
								color: #FF6F00;
								line-height: 45rpx;
								text-align: center;
							}
						}

						.recommend-bottom {
							display: flex;
							align-items: center;
							justify-content: space-between;

							.pirce {
								font-weight: 400;
								font-size: 24rpx;
								color: #FFFFFF;
								line-height: 33rpx;
								text-align: center;
							}

							.time {
								font-weight: 400;
								font-size: 24rpx;
								color: rgba(255, 255, 255, 0.8);
								line-height: 33rpx;
								text-align: center;
							}

						}
					}
				}
			}

		}
	}

	.ismore {
		width: 259rpx;
		height: 76rpx;
		background: rgba(216, 216, 216, 0);
		border-radius: 39rpx;
		border: 1rpx solid #979797;
		font-weight: 400;
		font-size: 28rpx;
		color: #FFFFFF;
		line-height: 76rpx;
		text-align: center;
		margin: 0 auto;
		margin-top: 28rpx;
	}

	.menu-item-btn {
		position: fixed;
		right: 0;
		bottom: 600rpx;
		padding: 0;
		margin: 0;
		width: 124rpx;
		height: 129rpx;
		background-image: url('https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/peng-jc/service-pp.png');
		background-color: transparent;
		background-repeat: no-repeat;
		background-size: cover;
	}
</style>